Passed
Pull Request — master (#195)
by
unknown
08:51
created

qucosa.js ➔ gndNothingFound   A

Complexity

Conditions 5

Size

Total Lines 31
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 18
dl 0
loc 31
rs 9.0333
c 0
b 0
f 0
1
/**
2
 * This file is part of the TYPO3 CMS project.
3
 *
4
 * It is free software; you can redistribute it and/or modify it under
5
 * the terms of the GNU General Public License, either version 2
6
 * of the License, or any later version.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 *
11
 * The TYPO3 project - inspiring people to share!
12
 */
13
14
var userNotifcationSettings = {
15
    init: function() {
16
17
        if (!jQuery("#notifyOnChanges").prop("checked")) {
18
            jQuery(".notifyOnChanges-child").prop("disabled","true");
19
        }
20
21
        jQuery("#notifyOnChanges").on("click", function(){
22
            if (jQuery(this).prop("checked")) {
23
                jQuery(this).parent().find(".notifyOnChanges-child").prop("disabled",false);
24
            } else {
25
                jQuery(this).parent().find(".notifyOnChanges-child").prop("disabled",true);
26
            }
27
        });
28
    }
29
}
30
var documentFormGroupSelector = {
31
    init() {
32
        var form = jQuery(".document-form-main");
33
        if (typeof form !== "undefined" && form.length > 0) {
34
35
            var activeGroup = form.data("activegroup");
36
            var activeGroupIndex = form.data("activegroupindex");
37
38
            var tab = jQuery('fieldset[data-group="' + activeGroup + '"]').parent().attr("id");
39
40
            if (typeof tab !== "undefined" && tab.length > 0) {
41
                jQuery('.nav-link').removeClass("active");
42
                jQuery('.tab-pane').removeClass("active");
43
                jQuery('.nav-link[href="#' + tab + '"]').addClass("active");
44
                jQuery('fieldset[data-group="' + activeGroup + '"]').parent().addClass("active");
45
46
                if (activeGroupIndex >= 0) {
47
                    var group = jQuery('fieldset[data-group="' + activeGroup + '"]:eq(' + activeGroupIndex + ')');
48
                    jQuery('html, body').animate({
49
                        scrollTop: jQuery(group).offset().top - 150
50
                    }, 0);
51
                } else {
52
                    var emptyGroupElement = jQuery('fieldset[data-group="' + activeGroup + '"][data-emptygroup="1"]').first();
53
54
                    if (emptyGroupElement.length > 0) {
55
                        activeGroupIndex = emptyGroupElement.data('groupindex');
56
                    } else {
57
                        activeGroupIndex = jQuery('fieldset[data-group="' + activeGroup + '"]').size();
58
                    }
59
60
                    if (activeGroupIndex > 0) {
61
                        addGroup(jQuery('button.add_group[data-group="' + activeGroup + '"]'));
62
                    }
63
64
                    if (form.data("addcurrentfeuser")) {
65
                        isGroupLoaded(
66
                            'fieldset[data-group="' + activeGroup + '"][data-groupindex="' + activeGroupIndex + '"]',
67
                            function () {
68
                                jQuery('.addMyData').hide();
69
                                var activeGroupElement = jQuery('fieldset[data-group="' + activeGroup + '"][data-groupindex="' + activeGroupIndex + '"]');
70
                                //var context = jQuery('#userSearchModal-'+activeGroupIndex).find('input');
71
                                var context = activeGroupElement.find('.addMyData').first();
72
                                setDataRequest(context.data('ajax'), jQuery('form').data('fispersid'), context);
73
                                jQuery('<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle pull-right"></i>' + form_info_msg_personid_added + '</div>').insertAfter(activeGroupElement.find('legend').last());
0 ignored issues
show
Bug introduced by
The variable form_info_msg_personid_added seems to be never declared. If this is a global, consider adding a /** global: form_info_msg_personid_added */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
74
                                jQuery('html, body').animate({
75
                                    scrollTop: jQuery(activeGroupElement).offset().top - 150
76
                                }, 0);
77
                            });
78
                    }
79
                }
80
            }
81
        }
82
    }
83
}
84
85
var isGroupLoaded = function (element, callback, counter = 0) {
86
    if (jQuery(element).length) {
87
        callback(jQuery(element));
88
    } else {
89
        if (counter < 10) {
90
            setTimeout(function () {
91
                isGroupLoaded(element, callback, counter++)
92
            }, 500);
93
        }
94
    }
95
}
96
97
var toggleBulkImportRecord = function() {
98
    jQuery(".bulk-import-checkbox").on("click", function() {
99
        var ajaxURL = jQuery(this).closest("tr").data('ajax');
100
        var params = {};
101
        jQuery.post(ajaxURL, params, function(data) {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
102
        });
103
    });
104
}
105
106
var toggleBulkImportAuthorSearch = function() {
107
    jQuery(".bulkImportAuthorSearch").on("click", function() {
108
        var ajaxURL = jQuery(this).data('ajax');
109
        var params = {};
110
        jQuery.post(ajaxURL, params, function(data) {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
111
        });
112
    });
113
}
114
115
var doctypeChange = {
116
117
    init() {
118
        var _this = this;
0 ignored issues
show
Unused Code introduced by
The variable _this seems to be never used. Consider removing it.
Loading history...
119
120
        jQuery("#confirmDoctypeChange .saveDocumentSummary").on("click", function (e) {
121
122
            var copyText = jQuery("#confirmDoctypeChange .modal-body .details-view").html();
123
124
            copyText = "<!DOCTYPE html>" +
125
                "<html lang=\"de\" dir=\"ltr\" class=\"no-js\">"+
126
                "<head>" +
127
                "<style>" +
128
                    ".details-group-name, .details-field-name {font-weight: bold;} " +
129
                    ".details-group-name {margin: 20px 0 5px 0; font-size: 18px} " +
130
                    ".details-field-name {font-size: 16px;} " +
131
                    ".details-group {list-style: none;}" +
132
                "</style>" +
133
                "</head>" +
134
                "<body>" + copyText + "</body>" +
135
                "</html>";
136
137
            var publication = new Blob([copyText], {type: "text/html;charset=utf-8"});
0 ignored issues
show
Bug introduced by
The variable Blob seems to be never declared. If this is a global, consider adding a /** global: Blob */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
138
            saveAs(publication, "publication.html");
139
140
            e.preventDefault();
141
        });
142
143
        jQuery("#confirmDoctypeChange .submitChangeDocumentType").on("click", function (e) {
144
            var documentType = jQuery('#changeDocumentTypeForm').find('select').val();
145
            if (documentType <= 0) {
146
                jQuery('#changeDocumentTypeForm').find('select').addClass('mandatory-error');
147
148
                jQuery('.modal-body').animate({
149
                    scrollTop:jQuery(jQuery('#changeDocumentTypeForm').find('select')).offset()
150
                }, 100);
151
152
                e.preventDefault();
153
            }
154
        });
155
156
        jQuery("#changeDocumentTypeForm select").on("change", function (e) {
157
            var documentType = jQuery('#changeDocumentTypeForm').find('select').val();
158
            if (documentType > 0) {
159
                jQuery('#changeDocumentTypeForm').find('select').removeClass('mandatory-error');
160
                e.preventDefault();
161
            }
162
        });
163
164
        jQuery("#confirmDoctypeChange").on("show.bs.modal", function(e) {
165
            jQuery(this).find("#changeDocumentTypeForm").attr("action", jQuery(e.relatedTarget).attr("href"));
166
        });
167
168
        jQuery("#confirmDoctypeChange").on("hidden.bs.modal", function(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
169
            jQuery('#changeDocumentTypeForm').find('select').removeClass('mandatory-error');
170
        });
171
    }
172
}
173
174
var documentFormGroupSelector = {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable documentFormGroupSelector already seems to be declared on line 30. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
175
    init() {
176
        var form = jQuery(".document-form-main");
177
        if (typeof form !== "undefined" && form.length > 0) {
178
179
            var activeGroup = form.data("activegroup");
180
            var activeGroupIndex = form.data("activegroupindex");
181
182
            var tab = jQuery('fieldset[data-group="' + activeGroup + '"]').parent().attr("id");
183
184
            if (typeof tab !== "undefined" && tab.length > 0) {
185
                jQuery('.nav-link').removeClass("active");
186
                jQuery('.tab-pane').removeClass("active");
187
                jQuery('.nav-link[href="#' + tab + '"]').addClass("active");
188
                jQuery('fieldset[data-group="' + activeGroup + '"]').parent().addClass("active");
189
190
                if (activeGroupIndex >= 0) {
191
                    group = jQuery('fieldset[data-group="' + activeGroup + '"]:eq(' + activeGroupIndex + ')');
0 ignored issues
show
Bug introduced by
The variable group seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.group.
Loading history...
192
                    jQuery('html, body').animate({
193
                        scrollTop: jQuery(group).offset().top - 150
194
                    }, 0);
195
                } else {
196
                    addGroup(jQuery('button.add_group[data-group="' + activeGroup + '"]'));
197
                }
198
            }
199
        }
200
    }
201
}
202
203
var saveExtendedSearch = {
204
205
    init: function () {
206
        this.show();
207
        this.save();
208
209
        jQuery("button").on("click", function () {
210
            jQuery(".alert-save-extended-search-success").hide();
211
        });
212
        
213
    },
214
215
    show: function() {
216
        jQuery("#save-extended-search").on("click", function (e) {
217
            jQuery('.alert-save-extended-search').hide();
218
            jQuery("#save-extended-search-dialog #extended-search-name").val("");
219
            jQuery("#save-extended-search-dialog").modal('show');
220
            e.preventDefault();
221
        });
222
    },
223
224
    save: function() {
225
        jQuery("#save-extended-search-dialog .modal-submit-button").on("click", function (e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
226
            var name = jQuery("#save-extended-search-dialog #extended-search-name").val();
227
            var query = jQuery("#extended-search-query").val();
228
            var ajaxURL = jQuery(this).data('ajax');
229
230
            if (query.length < 1 || name.length < 1) {
231
                jQuery('.alert-save-extended-search').show();
232
                return;
233
            }
234
235
            var res = ajaxURL.match(/(tx\w+?)%/); // get param name
236
            var params = {};
237
            var indexParam = {};
238
            if (res && res[1]) {
239
                indexParam['name'] = name;
240
                indexParam['query'] = query;
241
                params[res[1]] = indexParam;
242
            }
243
244
            jQuery.post(ajaxURL, params, function(data) {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
245
                jQuery("#save-extended-search-dialog").modal('hide');
246
                jQuery(".alert-save-extended-search-success").show();
247
                openExtendedSearch.loadList();
248
            }).fail(function() {
249
250
            })
251
        });
252
    }
253
}
254
255
256
var openExtendedSearch = {
257
258
    init: function () {
259
        this.loadList();
260
    },
261
262
    loadList: function() {
263
        var _this = this;
264
265
        if (jQuery("#load-extended-search").length) {
266
            var ajaxURL = jQuery("#load-extended-search-select").data('ajax');
267
            var params = {};
268
            jQuery.post(ajaxURL, params, function(data) {
269
                jQuery("#load-extended-search-select").length
0 ignored issues
show
introduced by
The result of the property access to jQuery("#load-extended-search-select").length is not used.
Loading history...
270
271
                jQuery("#load-extended-search-select .dropdown-item").remove();
272
273
                data.forEach(function(item){
274
                    if (item.name.length) {
275
                        jQuery(
276
                            '<a class="dropdown-item" ' +
277
                            'data-search-id="' + item.uid + '" ' +
278
                            'href="#">' + item.name + '</a>'
279
                        ).appendTo("#load-extended-search-select");
280
                    }
281
                });
282
283
                if (data.length) {
284
                    jQuery("#load-extended-search").removeAttr("disabled");
285
                } else {
286
                    jQuery("#load-extended-search").attr("disabled","disabled");
287
                }
288
289
                _this.onLoadSearch();
290
291
            }, "json");
292
        }
293
    },
294
295
    onLoadSearch: function() {
296
        jQuery("#load-extended-search-select .dropdown-item").on("click", function (e) {
297
            var ajaxURL = jQuery("#load-extended-search-select").data('ajax-load');
298
            var res = ajaxURL.match(/(tx\w+?)%/);
299
            var params = {};
300
            var indexParam = {};
301
            if (res && res[1]) {
302
                indexParam['id'] = jQuery(this).data("search-id");
303
                params[res[1]] = indexParam;
304
            }
305
306
            jQuery.post(ajaxURL, params, function(data) {
307
                jQuery("#extended-search-query").val(data);
308
            });
309
310
            e.preventDefault();
311
        });
312
    }
313
}
314
315
316
var extendedSearch = {
317
318
    init: function () {
319
        this.showAddFieldDialog();
320
        this.addField();
321
    },
322
323
    showAddFieldDialog: function () {
324
        jQuery("#extended-search-add-field .dropdown-item").on("click", function (e) {
325
            var field = jQuery(this).data("field");
326
            var formGroup = jQuery(this).data("form-group");
327
            var fieldType = jQuery(this).data("type");
328
            var fieldName = jQuery(this).text();
329
330
            jQuery("#add-searchfield-dialog .modal-field-name").text(fieldName);
331
            jQuery("#add-searchfield-dialog .modal-submit-button").data("field", field);
332
            jQuery("#add-searchfield-dialog .modal-submit-button").data("form-group", formGroup);
333
            jQuery("#add-searchfield-dialog .modal-submit-button").data("type", fieldType);
334
335
            jQuery("#add-searchfield-dialog").find(".search-field").addClass("d-none");
336
            jQuery("#add-searchfield-dialog").find(".search-field-" + formGroup).removeClass("d-none");
337
338
            // Reset operators
339
            jQuery("#add-searchfield-dialog #search-field-operator-binary option[value='AND']").prop('selected', true);
340
            jQuery("#add-searchfield-dialog #search-field-operator-unary option[value='']").prop('selected', true);
341
342
            // Reset field values
343
            jQuery("#add-searchfield-dialog .search-field-value").val("");
344
345
            jQuery(".modal-footer").find("[data-target='#FisSearchModal-persons']").hide();
346
            jQuery(".modal-footer").find("[data-target='#FisSearchModal-affiliation']").hide();
347
348
            if (field == 'persons') {
349
                jQuery(".modal-footer").find("[data-target='#FisSearchModal-persons']").show();
350
            }
351
352
            if (field == 'affiliation') {
353
                jQuery(".modal-footer").find("[data-target='#FisSearchModal-affiliation']").show();
354
            }
355
356
            jQuery("#add-searchfield-dialog").modal('show');
357
358
            e.preventDefault();
359
        });
360
    },
361
362
    addField: function () {
363
364
        var _this = this;
365
366
        jQuery("#add-searchfield-dialog .modal-submit-button").on("click", function (e) {
367
            var field = jQuery(this).data("field");
368
            var fieldType = jQuery(this).data("type");
369
            var formGroup = jQuery(this).data("form-group");
370
371
            var operatorBinary = jQuery("#search-field-operator-binary").val();
372
            var operatorUnary = jQuery("#search-field-operator-unary").val();
373
374
            var fieldPart = "";
375
376
            switch(fieldType) {
377
                case "date-range":
378
                    fieldPart = _this.dateRangeField(formGroup, field);
379
                    break;
380
                case "year-range":
381
                    fieldPart = _this.yearRangeField(formGroup, field);
382
                    break;
383
                case "phrase":
384
                    fieldPart = _this.valueField(formGroup, field, true);
385
                    break;
386
                default:
387
                    fieldPart = _this.valueField(formGroup, field);
388
                    break;
389
            }
390
391
            if (fieldPart.length > 0) {
392
393
                var query = jQuery("#extended-search-query").val();
394
395
                if (query.length > 0) {
396
                    query += (operatorBinary) ? " " + operatorBinary + " " : " AND ";
397
                }
398
399
                if (operatorUnary == "NOT") {
400
                    fieldPart = "NOT(" + fieldPart + ")";
401
                }
402
403
                query += fieldPart;
404
405
                jQuery("#extended-search-query").val(query);
406
            }
407
408
            jQuery("#add-searchfield-dialog").modal('hide');
409
            e.preventDefault();
410
        });
411
    },
412
413
    valueField: function(group, field, phrase = false) {
414
415
        var value = jQuery(".search-field-"+group+" .search-field-value").val();
416
417
        if (phrase) {
418
            value = '"'+value+'"';
419
        }
420
421
        var fieldPart = "";
422
423
        if (value.length > 0) {
424
425
            fieldPart += field + ":" + value;
426
        }
427
428
        return fieldPart;
429
    },
430
431
    yearRangeField: function(group, field) {
432
433
        var from = jQuery(".search-field-"+group+" .search-field-from").val();
434
        var to =   jQuery(".search-field-"+group+" .search-field-to").val();
435
436
        var fieldPart = "";
437
438 View Code Duplication
        if (from.length > 0 && to.length > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
439
            fieldPart = field+":["+from+" TO "+to+"]";
440
        } else {
441
            if (from.length == 0 && to.length == 0) {
0 ignored issues
show
Best Practice introduced by
Comparing to.length to 0 using the == operator is not safe. Consider using === instead.
Loading history...
Best Practice introduced by
Comparing from.length to 0 using the == operator is not safe. Consider using === instead.
Loading history...
442
                return "";
443
            }
444
445
            from = (from.length > 0)? from : "*";
446
            to = (to.length > 0)? to : "*";
447
            fieldPart = field+":["+from+" TO "+to+"]";
448
        }
449
450
        return fieldPart;
451
    },
452
453
454
    dateRangeField: function(group, field) {
455
456
        var from = jQuery(".search-field-"+group+" .search-field-from").val();
457
        var to =   jQuery(".search-field-"+group+" .search-field-to").val();
458
459
        var fieldPart = "";
460
461
        var fromDate = moment(from, "DD.MM.YYYY");
462
        if (fromDate.format("DD.MM.YYYY") == from) {
463
            from = fromDate.format("YYYY-MM-DD");
464
        } else {
465
            from = "";
466
        }
467
468
        var toDate = moment(to, "DD.MM.YYYY");
469
        if (toDate.format("DD.MM.YYYY") == to) {
470
            to = toDate.format("YYYY-MM-DD");
471
        } else {
472
            to = "";
473
        }
474
475 View Code Duplication
        if (from.length > 0 && to.length > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
476
            fieldPart = field+":["+from+" TO "+to+"]";
477
        } else {
478
            if (from.length == 0 && to.length == 0) {
0 ignored issues
show
Best Practice introduced by
Comparing to.length to 0 using the == operator is not safe. Consider using === instead.
Loading history...
Best Practice introduced by
Comparing from.length to 0 using the == operator is not safe. Consider using === instead.
Loading history...
479
                return "";
480
            }
481
482
            from = (from.length > 0)? from : "*";
483
            to = (to.length > 0)? to : "*";
484
            fieldPart = field+":["+from+" TO "+to+"]";
485
        }
486
487
        return fieldPart;
488
    }
489
}
490
491
function getWorkspaceListAction() {
492
    return jQuery("#batchForm").attr("data-workspace-list-action");
493
}
494
495
496
var selectFilter = function(selectFilterId, searchInput = false) {
497
    selectFilterId = '#'+selectFilterId;
498
499
    var options = {};
500
    if (!searchInput) {
501
        options['minimumResultsForSearch'] = 'Infinity';
502
    }
503
504
    jQuery(selectFilterId).select2(options);
505
506
    jQuery(selectFilterId).on("select2:select", function(e) {
507
        var data = e.params.data;
508
509
510
        var filterName = jQuery(selectFilterId).attr('name');
511
        var filterValue = [];
512
        if (e.params.data.id) {
513
            filterValue = [e.params.data.id];
514
        }
515
        var ajaxURL = jQuery(selectFilterId).parent().data('ajax');
516
517
        var res = ajaxURL.match(/(tx\w+?)%/); // get param name
518
        var params = {};
519
        var indexParam = {};
520
        if (res && res[1]) {
521
            indexParam['name'] = filterName;
522
            indexParam['values'] = filterValue;
523
            params[res[1]] = indexParam;
524
        }
525
526
        jQuery.post(ajaxURL, params, function(data) {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
527
            window.location.href = getWorkspaceListAction();
528
        });
529
530
    });
531
}
532
533
534
var toggleDiscardedFilter = function() {
535
    jQuery("#hideDiscarded").on("click", function() {
536
        var ajaxURL = jQuery(this).data('ajax');
537
        var params = {};
538
        jQuery.post(ajaxURL, params, function(data) {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
539
            window.location.href = getWorkspaceListAction();
540
        });
541
542
    });
543
}
544
545
var toggleBookmarksOnly = function() {
546
    jQuery("#bookmarksOnly").on("click", function() {
547
        var ajaxURL = jQuery(this).data('ajax');
548
        var params = {};
549
        jQuery.post(ajaxURL, params, function(data) {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
550
            window.location.href = getWorkspaceListAction();
551
        });
552
553
    });
554
}
555
556
557
var selectSort = function() {
558
    jQuery(".sort-button").on("click", function(element){
0 ignored issues
show
Unused Code introduced by
The parameter element is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
559
560
        var field = jQuery(this).attr('data-field');
561
        var order = jQuery(this).attr('data-order');
562
        var ajaxURL = jQuery(this).parent().data('ajax');
563
564
        var res = ajaxURL.match(/(tx\w+?)%/); // get param name
565
        var params = {};
566
        var indexParam = {};
567
        if (res && res[1]) {
568
            indexParam['field'] = field;
569
            indexParam['order'] = order;
570
            params[res[1]] = indexParam;
571
        }
572
573
        jQuery.post(ajaxURL, params, function(data) {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
574
            window.location.href = getWorkspaceListAction();
575
        });
576
    })
577
}
578
579
580
var batchConfirmDialog = function(actionName) {
581
582
    jQuery("#batchButton"+actionName).on("click", function(e) {
583
        jQuery("#batchAction"+actionName).removeAttr("disabled")
584
        jQuery("#confirmWorkspace"+actionName).modal('show');
585
        e.preventDefault();
586
    });
587
588
    jQuery("#confirmWorkspace"+actionName).on('hidden.bs.modal', function(){
589
        jQuery(".batchAction").attr("disabled","disabled")
590
    });
591
}
592
593
var addBookmarkHandler = {
594
    init() {
595
        jQuery(".add-bookmark").on("click", function(e) {
596
            var button = jQuery(this);
597
            var ajaxURL = jQuery(this).data('ajax');
598
            var identifier = jQuery(this).data('id');
599
600
            var res = ajaxURL.match(/(tx\w+?)%/); // get param name
601
            var params = {};
602
            var indexParam = {};
603
            if (res && res[1]) {
604
                indexParam['identifier'] = identifier;
605
                params[res[1]] = indexParam;
606
            }
607
608
            jQuery.post(ajaxURL, params, function(data) {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
609
                button.find("span").removeClass("d-none");
610
            }).done(function() {
611
                setTimeout(function() {
612
                    button.find("span").addClass("d-none");
613
                    button.addClass("disabled");
614
                }, 500);
615
            }).fail(function() {
616
            }).always(function() {
617
            });
618
619
            e.preventDefault();
620
        });
621
622
    }
623
}
624
625
var removeBookmarkHandler = {
626
    init() {
627
        jQuery(".remove-bookmark").on("click", function(e) {
628
629
            var identifier = jQuery(this).attr("data-id");
630
631
            jQuery("#confirmWorkspaceRemoveBookmark .documentIdentifier").val(identifier);
632
            jQuery("tr[data-id='"+identifier+"']").addClass("table-danger");
633
            jQuery("#confirmWorkspaceRemoveBookmark").modal('show');
634
635
            jQuery("#confirmWorkspaceRemoveBookmark").on('hidden.bs.modal', function(){
636
                jQuery("tr[data-id='"+identifier+"']").removeClass("table-danger");
637
            });
638
639
            e.preventDefault();
640
        });
641
    }
642
}
643
644
var batchSelectHandler = {
645
646
    init() {
647
        var _this = this;
648
649
        this.refreshToggleButtons();
650
651
        jQuery(".workspace-select-toggle").removeClass("d-none");
652
653
        jQuery(".workspace-select-toggle").on("click", function(e){
654
655
            if (jQuery(".batch-checkbox:checked").length) {
656
                jQuery(".batch-checkbox").each(function() {
657
                    jQuery(this).prop("checked", false);
658
                });
659
            } else {
660
                jQuery(".batch-checkbox").each(function() {
661
                    jQuery(this).prop("checked", true);
662
                });
663
            }
664
665
            _this.refreshToggleButtons();
666
667
            e.preventDefault();
668
        });
669
670
        jQuery(".batch-checkbox").on("click", function() {
671
            _this.refreshToggleButtons();
672
        });
673
    },
674
    refreshToggleButtons() {
675
        this.toggleSelectButton();
676
        this.toggleRegisterButton();
677
        this.toggleSetInProgressButton();
678
        this.toggleBatchRemoveButton();
679
        this.toggleBatchReleaseButton();
680
        this.toggleBatchBookmarkButton();
681
    },
682
    toggleSelectButton() {
683
        if (jQuery(".batch-checkbox:checked").length > 0) {
684
            jQuery(".workspace-select-all").show();
685
            jQuery(".workspace-unselect-all").hide();
686
        } else {
687
            jQuery(".workspace-select-all").hide();
688
            jQuery(".workspace-unselect-all").show();
689
        }
690
    },
691
    toggleRegisterButton() {
692
        if (jQuery('#workspace-list [data-alias-state="new"] .batch-checkbox:checked').length > 0) {
693
            jQuery("#batchButtonBatchRegister").removeClass("disabled");
694
        } else {
695
            jQuery("#batchButtonBatchRegister").addClass("disabled");
696
        }
697
    },
698
    toggleSetInProgressButton() {
699
        var numNew = jQuery('#workspace-list tbody tr td[data-alias-state="new"]:first-child .batch-checkbox:checked').length;
700
        var numInProgress = jQuery('#workspace-list tbody tr td[data-alias-state="in_progress"]:first-child .batch-checkbox:checked').length;
701
        var numChecked = jQuery(".batch-checkbox:checked").length;
702
703
        if (numNew + numInProgress < numChecked) {
704
            jQuery("#batchButtonBatchSetInProgress").removeClass("disabled");
705
        } else {
706
            jQuery("#batchButtonBatchSetInProgress").addClass("disabled");
707
        }
708
    },
709
    toggleBatchRemoveButton() {
710
        if (jQuery('#workspace-list [data-bookmark="1"] .batch-checkbox:checked').length > 0) {
711
            jQuery("#batchButtonBatchRemove").removeClass("disabled");
712
        } else {
713
            jQuery("#batchButtonBatchRemove").addClass("disabled");
714
        }
715
    },
716
    toggleBatchBookmarkButton: function() {
717
718
        if (jQuery('#workspace-list .batch-checkbox:checked').length < 1) {
719
            jQuery("#batchButtonBatchBookmark").addClass("disabled");
720
        }
721
722
        jQuery('#workspace-list .batch-checkbox:checked').each(function(){
723
            if (jQuery(this).parent().data("alias-state") != "new") {
724
                jQuery("#batchButtonBatchBookmark").removeClass("disabled");
725
            }
726
        });
727
    },
728
    toggleBatchReleaseButton() {
729
        var countChecked = jQuery('#workspace-list .batch-checkbox:checked').length;
730
        var countCheckedNew = jQuery('#workspace-list [data-alias-state="new"] .batch-checkbox:checked').length;
731
        var countCheckedReleased = jQuery('#workspace-list [data-alias-state="released"] .batch-checkbox:checked').length;
732
733
        if (countChecked - (countCheckedNew + countCheckedReleased) > 0) {
734
            jQuery("#batchButtonBatchReleaseUnvalidated").removeClass("disabled");
735
            jQuery("#batchButtonBatchReleaseValidated").removeClass("disabled");
736
        } else {
737
            jQuery("#batchButtonBatchReleaseUnvalidated").addClass("disabled");
738
            jQuery("#batchButtonBatchReleaseValidated").addClass("disabled");
739
        }
740
    }
741
}
742
743
var itemsPerPageHandler = {
744
    init() {
745
746
        jQuery("#items-up").on("click", function(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
747
            var itemsPerPage = jQuery("#items-per-page").val();
748
            var items = parseInt(itemsPerPage, 10);
749
750
            if (itemsPerPage == items) {
751
                items += 10;
752
            } else {
753
                items = 10;
754
            }
755
            jQuery("#items-per-page").val(items);
756
        });
757
758
        jQuery("#items-down").on("click", function(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
759
            var itemsPerPage = jQuery("#items-per-page").val();
760
            var items = parseInt(itemsPerPage, 10);
761
762
            if (itemsPerPage === items.toString()) {
763
                items = (items <= 10)? items : items-10;
764
            } else {
765
                items = 10;
766
            }
767
            jQuery("#items-per-page").val(items);
768
        });
769
770
        jQuery("#items-per-page-save").on("click", function(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
771
            var button = jQuery(this);
0 ignored issues
show
Unused Code introduced by
The variable button seems to be never used. Consider removing it.
Loading history...
772
            var ajaxURL = jQuery(this).data('ajax');
773
            var itemsPerPage = jQuery("#items-per-page").val();
774
775
            var items = parseInt(itemsPerPage, 10);
776
777
            if (itemsPerPage !== items.toString() || items < 1) {
778
                items = 10;
779
            }
780
            
781
            var res = ajaxURL.match(/(tx\w+?)%/); // get param name
782
            var params = {};
783
            var indexParam = {};
784
            if (res && res[1]) {
785
                indexParam['itemsPerPage'] = items;
786
                params[res[1]] = indexParam;
787
            }
788
789
            jQuery.post(ajaxURL, params, function(data) {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
790
                window.location.href = getWorkspaceListAction();
791
            });
792
793
        });
794
795
    }
796
}
797
798
var validateFormAndSave = function() {
799
    jQuery("#validDocument").val("0");
800
    if (validateForm()) {
801
        jQuery("#validDocument").val("1");
802
803
        jQuery("#new-document-form #save").prop("disabled", true);
804
805
        jQuery("#new-document-form").submit();
806
807
        return true;
808
    }
809
    return false;
810
}
811
var validateFormOnly = function() {
812
    if (validateForm()) {
813
        showFormSuccess();
814
    }
815
    return false;
816
}
817
var validateForm = function() {
818
    var error = false;
819
    jQuery("span.mandatory-error").remove();
820
    jQuery("div.alert").remove();
821
    jQuery(".tx-dpf-tabs li a").each(function() {
822
        jQuery(this).removeClass("mandatory-error");
823
    });
824
    jQuery(".input-field[data-mandatory]").each(function() {
825
        jQuery(this).removeClass("mandatory-error");
826
    });
827
828
    // check mandatory groups
829
    var search = 'fieldset[data-mandatory="'+constants['mandatory']+'"]';
0 ignored issues
show
Bug introduced by
The variable constants seems to be never declared. If this is a global, consider adding a /** global: constants */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
830
    if (hasFiles()) {
831
        search = search + ',fieldset[data-mandatory="'+constants['mandatory_file_only']+'"]';
832
    }
833
    jQuery(search).each(function() {
834
        var fieldset = jQuery(this);
835
        if (hasMandatoryInputs(fieldset)) {
836
            if (checkMandatoryInputs(fieldset)) {
837
                jQuery('<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle pull-right"></i>' + form_error_msg_group_mandatory + '</div>').insertAfter(fieldset.find("legend").last());
0 ignored issues
show
Bug introduced by
The variable form_error_msg_group_mandatory seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_group_mandatory */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
838
                showFormError();
839
                error = true;
840
                markPage(fieldset, true);
841
            }
842
        } else {
843
            if (checkFilledInputs(fieldset)) {
844
                jQuery('<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle pull-right"></i>' + form_error_msg_group_one_required + '</div>').insertAfter(fieldset.find("legend").last());
0 ignored issues
show
Bug introduced by
The variable form_error_msg_group_one_required seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_group_one_required */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
845
                showFormError();
846
                error = true;
847
                markPage(fieldset, true);
848
                error = true;
849
            }
850
        }
851
    });
852
    jQuery("fieldset[id=primary_file]").each(function() {
853
        var fieldset = jQuery(this);
854
        if (checkPrimaryFile(fieldset)) {
855
            jQuery('<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle pull-right"></i>' + form_error_msg_group_mandatory + '</div>').insertBefore(fieldset.find("legend").last());
0 ignored issues
show
Bug introduced by
The variable form_error_msg_group_mandatory seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_group_mandatory */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
856
            showFormError();
857
            error = true;
858
            markPage(fieldset, true);
859
        }
860
    });
861
    // check non mandatory groups
862
    jQuery('fieldset[data-mandatory=""],fieldset[data-mandatory="0"]').each(function() {
863
        var fieldset = jQuery(this);
864
        var filledInputs = 0;
865
        jQuery(this).find(".input-field").each(function() {
866
            var id = jQuery(this).attr("id");
867
            if (
868
                ((jQuery(this).attr("type") != "checkbox" && jQuery(this).val()) || (jQuery(this).attr("type") == "checkbox" && (jQuery("#" + id + ":checked").length > 0))) &&
869
                jQuery(this).attr("data-default") != "1"
870
            ) {
871
                filledInputs++;
872
            }
873
            //if (jQuery(this).val() && jQuery(this).attr("data-default") != "1") {
874
            //    filledInputs++;
875
            //}
876
            jQuery(this).removeClass("mandatory-error");
877
        });
878
        // if there are fields with a value then mandatory fields
879
        // are relevant.
880
        if (filledInputs) {
881
            if (checkMandatoryInputs(fieldset)) {
882
                jQuery('<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle pull-right"></i>' + form_error_msg_group_mandatory + '</div>').insertAfter(fieldset.find("legend").last());
0 ignored issues
show
Bug introduced by
The variable form_error_msg_group_mandatory seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_group_mandatory */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
883
                showFormError();
884
                markPage(fieldset, true);
885
                error = true;
886
            }
887
        }
888
    });
889
    jQuery("fieldset").each(function() {
890
        var fieldset = jQuery(this);
891
        fieldset.find(".input-field").each(function() {
892
            jQuery(this).removeClass("invalid-error");
893
            var validation = jQuery(this).attr("data-regexp");
894
            if (jQuery(this).val() && jQuery(this).val().length > 0 && validation && validation.length > 0) {
895
                try {
896
                    var regexp = new RegExp(validation);
897
                    var res = jQuery(this).val().match(regexp);
898
                    if (!(res && res.length == 1 && res[0] == jQuery(this).val())) {
0 ignored issues
show
Best Practice introduced by
Comparing res.length to 1 using the == operator is not safe. Consider using === instead.
Loading history...
899
                        jQuery('<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle pull-right"></i>' + form_error_msg_field_invalid + ': ' + jQuery(this).attr("data-label") + '</div>').insertAfter(fieldset.find("legend").last());
0 ignored issues
show
Bug introduced by
The variable form_error_msg_field_invalid seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_field_invalid */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
900
                        jQuery(this).addClass("invalid-error");
901
                        showFormError();
902
                        markPage(fieldset, true);
903
                        error = true;
904
                    }
905
                } catch (err) {
906
                    jQuery('<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle pull-right"></i>' + form_error_msg_field_invalid + ': ' + jQuery(this).attr("data-label") + '</div>').insertAfter(fieldset.find("legend").last());
907
                    jQuery(this).addClass("invalid-error");
908
                    showFormError();
909
                    markPage(fieldset, true);
910
                    error = true;
911
                }
912
            } else {
913
                var validateDate = jQuery(this).attr("data-datatype") == 'DATE';
914
                if (jQuery(this).val() && jQuery(this).val().length > 0 && validateDate && !isDate(jQuery(this).val())) {
915
                    jQuery('<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle pull-right"></i>' + form_error_msg_field_invalid + ': ' + jQuery(this).attr("data-label") + '</div>').insertAfter(fieldset.find("legend").last());
916
                    jQuery(this).addClass("invalid-error");
917
                    showFormError();
918
                    markPage(fieldset, true);
919
                    error = true;
920
                }
921
            }
922
923
            var maxLength = jQuery(this).attr("data-maxlength");
924
            if (maxLength && maxLength > 0) {
925
                if (jQuery(this).val().length > maxLength) {
926
                    var max_lengrth_msg = form_error_msg_field_max_length.replace(/%s/gi, maxLength);
0 ignored issues
show
Bug introduced by
The variable form_error_msg_field_max_length seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_field_max_length */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
927
                    jQuery('<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle pull-right"></i>' + max_lengrth_msg + jQuery(this).attr("data-label") + '</div>').insertAfter(fieldset.find("legend").last());
928
                    jQuery(this).addClass("invalid-error");
929
                    showFormError();
930
                    markPage(fieldset, true);
931
                    error = true;
932
                }
933
            }
934
        });
935
    });
936
937
    return !error;
938
}
939
var showFormError = function() {
940
    jQuery(".tx-dpf div.alert-danger").remove();
941
    jQuery('<div class="alert alert-danger" role="alert"><i class="fab fa-gripfire pull-right"></i>' + form_error_msg + '</div>').insertBefore(jQuery(".tx-dpf form.document-form-main").first());
0 ignored issues
show
Bug introduced by
The variable form_error_msg seems to be never declared. If this is a global, consider adding a /** global: form_error_msg */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
942
    jQuery("html, body").animate({
943
        scrollTop: 0
944
    }, 200);
945
}
946
var showFormSuccess = function() {
947
    jQuery(".tx-dpf div.alert-danger").remove();
948
    jQuery('<div class="alert alert-success" role="alert"><i class="fab fa-gripfire pull-right"></i>' + form_success_msg + '</div>').insertBefore(jQuery(".tx-dpf form.document-form-main").first());
0 ignored issues
show
Bug introduced by
The variable form_success_msg seems to be never declared. If this is a global, consider adding a /** global: form_success_msg */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
949
    jQuery("html, body").animate({
950
        scrollTop: 0
951
    }, 200);
952
}
953
954
955
var hasFiles = function() {
956
    var $hasFiles = 0;
957
    jQuery(".input_file_upload").each(function() {
958
        if (jQuery(this).val()) {
959
            $hasFiles++;
960
        }
961
    });
962
    jQuery(".fs_file_group .file_link").each(function() {
963
        if (jQuery(this).attr("href")) {
964
            $hasFiles++;
965
        }
966
    });
967
968
    return $hasFiles > 0;
969
}
970
971
var hasMandatoryInputs = function(fieldset) {
972
    var search = '.input-field[data-mandatory="'+constants['mandatory']+'"]';
0 ignored issues
show
Bug introduced by
The variable constants seems to be never declared. If this is a global, consider adding a /** global: constants */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
973
    if (hasFiles()) {
974
        search = search + ',.input-field[data-mandatory="'+constants['mandatory_file_only']+'"]';
975
    }
976
    var inputs = fieldset.find(search);
977
    return inputs.length > 0
978
}
979
var markPage = function(fieldset, error) {
980
    var pageId = fieldset.parent().attr("id");
981
    var page = jQuery('.tx-dpf-tabs li a[href="#' + pageId + '"]');
982
    if (error) {
983
        page.addClass("mandatory-error");
984
    } else {
985
        page.removeClass("mandatory-error");
986
    }
987
}
988
var checkMandatoryInputs = function(fieldset) {
989
    var mandatoryError = false;
990
    var search = '.input-field[data-mandatory="'+constants['mandatory']+'"]';
0 ignored issues
show
Bug introduced by
The variable constants seems to be never declared. If this is a global, consider adding a /** global: constants */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
991
    if (hasFiles()) {
992
        search = search + ',.input-field[data-mandatory="'+constants['mandatory_file_only']+'"]';
993
    }
994
    fieldset.find(search).each(function() {
995
        var id = jQuery(this).attr("id");
996
        if ((jQuery(this).attr("type") != "checkbox" && !jQuery(this).val()) || (jQuery(this).attr("type") == "checkbox" && (jQuery("#" + id + ":checked").length != 1 || !jQuery("#" + id + ":checked")))) {
0 ignored issues
show
Best Practice introduced by
Comparing jQuery("#" + id + ":checked").length to 1 using the != operator is not safe. Consider using !== instead.
Loading history...
997
            mandatoryError = mandatoryError || true;
998
            jQuery(this).addClass("mandatory-error");
999
        } else {
1000
            jQuery(this).removeClass("mandatory-error");
1001
        }
1002
    });
1003
    return mandatoryError;
1004
}
1005
var checkPrimaryFile = function(fieldset) {
1006
    var mandatoryError = false;
1007
    fieldset.find("input#inp_primaryFile[data-primaryfilemandatory=1]").each(function() {
1008
        if (!jQuery(this).val()) {
1009
            mandatoryError = mandatoryError || true;
1010
            jQuery(this).addClass("mandatory-error");
1011
        } else {
1012
            jQuery(this).removeClass("mandatory-error");
1013
        }
1014
    });
1015
    return mandatoryError;
1016
}
1017
var checkFilledInputs = function(fieldset) {
1018
    var filledInputs = 0;
1019
    fieldset.find(".input-field").each(function() {
1020
        var id = jQuery(this).attr("id");
1021
        if (
1022
            ((jQuery(this).attr("type") != "checkbox" && jQuery(this).val()) || (jQuery(this).attr("type") == "checkbox" && (jQuery("#" + id + ":checked").length > 0))) &&
1023
            jQuery(this).attr("data-default") != "1"
1024
        ) {
1025
            filledInputs++;
1026
        }
1027
        //if (jQuery(this).val()) {
1028
        //    filledInputs++;
1029
        //}
1030
        jQuery(this).removeClass("mandatory-error");
1031
    });
1032
    return filledInputs < 1;
1033
}
1034
var addGroup = function(target) {
1035
1036
    var element = jQuery(target);
0 ignored issues
show
Unused Code introduced by
The variable element seems to be never used. Consider removing it.
Loading history...
1037
1038
    var dataGroup = jQuery(target).attr("data-group");
1039
1040
    // Number of the next group item
1041
    var groupIndex = parseInt(jQuery(target).attr("data-index")) + 1;
1042
1043
    jQuery(target).attr("data-index", groupIndex);
1044
    var ajaxURL = jQuery(target).attr("data-ajax");
1045
    var params = buildAjaxParams(ajaxURL, "groupIndex", groupIndex);
1046
    //do the ajax-call
1047
    jQuery.post(ajaxURL, params, function(group) {
1048
        var group = jQuery(group).find("fieldset");
1049
        // add the new group
1050
        jQuery(group).css({
1051
            'display': 'none'
1052
        }).insertAfter(jQuery('fieldset[data-group="' + dataGroup + '"]').last());
1053
        var height = jQuery('fieldset[data-group="' + dataGroup + '"]').last().outerHeight(true);
0 ignored issues
show
Unused Code introduced by
The variable height seems to be never used. Consider removing it.
Loading history...
1054
1055
        jQuery(group).fadeIn();
1056
1057
        jQuery("html, body").animate({
1058
            scrollTop: jQuery(group).offset().top - 150
1059
        }, 100);
1060
1061
        buttonFillOutServiceUrn();
1062
        datepicker();
1063
        addRemoveFileButton();
1064
        userSearch(group);
1065
        userSearchModalFillout();
1066
        addMyUserData();
1067
1068
        // gnd autocomplete for new groups
1069
        var gndField = jQuery(group).find(".gnd");
1070
        if (gndField.length != 0) {
0 ignored issues
show
Best Practice introduced by
Comparing gndField.length to 0 using the != operator is not safe. Consider using !== instead.
Loading history...
1071
            setGndAutocomplete(gndField.data("field"),gndField.data("groupindex"));
1072
        }
1073
    });
1074
    return false;
1075
}
1076
var addField = function() {
1077
    var addButton = jQuery(this);
1078
    // Get the field uid
1079
    var dataField = jQuery(this).attr("data-field");
0 ignored issues
show
Unused Code introduced by
The variable dataField seems to be never used. Consider removing it.
Loading history...
1080
    // Number of the next field item
1081
    var fieldIndex = parseInt(jQuery(this).attr("data-index")) + 1;
1082
    jQuery(this).attr("data-index", fieldIndex);
1083
    var ajaxURL = jQuery(this).attr("data-ajax");
1084
    var params = buildAjaxParams(ajaxURL, "fieldIndex", fieldIndex);
1085
    //do the ajax-call
1086
    jQuery.post(ajaxURL, params, function(element) {
1087
        var field = jQuery(element).find("#new-element").children();
1088
        jQuery(field).css({
1089
            "display": "none"
1090
        }).insertBefore(addButton).fadeIn();
1091
        buttonFillOutServiceUrn();
1092
        datepicker();
1093
1094
        // gnd autocomplete for new fields
1095
        var gndField = jQuery(element).find(".gnd");
1096
        if (gndField.length != 0) {
0 ignored issues
show
Best Practice introduced by
Comparing gndField.length to 0 using the != operator is not safe. Consider using !== instead.
Loading history...
1097
            setGndAutocomplete(gndField.data("field"),gndField.data("groupindex"));
1098
        }
1099
    });
1100
    return false;
1101
}
1102
var deleteFile = function() {
1103
    var fileGroup = jQuery(this).parent().parent();
1104
    var ajaxURL = jQuery(this).attr("data-ajax");
1105
    var params = {}
1106
        //do the ajax-call
1107
    jQuery.post(ajaxURL, params, function(element) {
1108
        var field = jQuery(element).find("#new-element").children();
1109
        jQuery(fileGroup).replaceWith(field);
1110
    });
1111
    return false;
1112
}
1113
1114
function buildAjaxParams(ajaxURL, indexName, index) {
1115
    var res = ajaxURL.match(/(tx\w+?)%/); // get param name
1116
    var params = {};
1117
    var indexParam = {};
1118
    if (res && res[1]) {
1119
        indexParam[indexName] = index;
1120
        params[res[1]] = indexParam;
1121
    }
1122
    return params;
1123
}
1124
var fillOutServiceUrn = function() {
1125
    // Get the field uid
1126
    var fieldUid = jQuery(this).attr("data-field");
1127
    var fieldIndex = jQuery(this).attr("data-index");
1128
    var groupUid = jQuery(this).attr("data-group");
1129
    var groupIndex = jQuery(this).attr("data-groupindex");
1130
    var ajaxURL = jQuery(this).attr("data-ajax");
1131
    var qucosaId = jQuery("#qucosaid").val();
1132
    var params = {};
0 ignored issues
show
Unused Code introduced by
The assignment to variable params seems to be never used. Consider removing it.
Loading history...
1133
    if (qucosaId) {
1134
        params = buildAjaxParams(ajaxURL, "qucosaId", qucosaId);
1135
    } else {
1136
        params = buildAjaxParams(ajaxURL, "qucosaId", "");
1137
    }
1138
1139
    var group = $(this).closest(".fs_group");
1140
1141
    //do the ajax-call
1142
    jQuery.post(ajaxURL, params, function(element) {
1143
1144
        group.find(".alert-filloutservice-urn").remove();
1145
1146
        if (element.error) {
1147
            var errorMsg = $('<div class="alert alert-danger alert-filloutservice-urn" role="alert"><i class="fab fa-gripfire pull-right"></i>' + form_error_msg_filloutservice + '</div>');
0 ignored issues
show
Bug introduced by
The variable form_error_msg_filloutservice seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_filloutservice */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1148
            errorMsg.insertAfter(group.find("legend"));
1149
            $("html, body").animate({scrollTop: group.offset().top}, 200);
1150
        } else {
1151
            jQuery("#qucosaid").val(element.qucosaId);
1152
            jQuery("#qucosaUrn").val(element.value);
1153
            var inputField = jQuery('.input-field[data-field="' + fieldUid + '"][data-index="' + fieldIndex + '"][data-group="' + groupUid + '"][data-groupindex="' + groupIndex + '"]');
1154
            inputField.val(element.value);
1155
            buttonFillOutServiceUrn();
1156
        }
1157
    }, "json");
1158
1159
    return false;
1160
}
1161
var buttonFillOutServiceUrn = function() {
1162
    jQuery("input.urn").each(function() {
1163
        var fieldUid = jQuery(this).attr("data-field");
1164
        var fieldIndex = jQuery(this).attr("data-index");
1165
        var groupUid = jQuery(this).attr("data-group");
0 ignored issues
show
Unused Code introduced by
The variable groupUid seems to be never used. Consider removing it.
Loading history...
1166
        var groupIndex = jQuery(this).attr("data-groupindex");
0 ignored issues
show
Unused Code introduced by
The variable groupIndex seems to be never used. Consider removing it.
Loading history...
1167
        var fillOutButton = jQuery('.fill_out_service_urn[data-field="' + fieldUid + '"][data-index="' + fieldIndex + '"]');
1168
        if ((jQuery(this).val() && jQuery(this).val().length > 0) || hasQucosaUrn()) {
1169
            fillOutButton.hide();
1170
        } else {
1171
            fillOutButton.show();
1172
        }
1173
    });
1174
    return false;
1175
}
1176
var hasQucosaUrn = function() {
1177
    var result = false;
1178
    var qucosaUrn = jQuery("#qucosaUrn").val();
1179
    jQuery("input.urn").each(function() {
1180
        var currentUrn = jQuery(this).val();
1181
        if (currentUrn && qucosaUrn && (currentUrn == qucosaUrn)) {
1182
            result = result || true;
1183
        }
1184
    });
1185
    return result;
1186
}
1187
var continuousScroll = function() {
1188
    var ajaxURL = jQuery("#next").attr("href");
1189
    jQuery.ajax({
1190
        url: ajaxURL,
1191
        success: function(html) {
1192
            if (html) {
1193
                jQuery(html).find("table tbody tr").each(function() {
1194
                    jQuery("#search-results tbody tr").last().parent().append(this);
1195
                });
1196
                if (jQuery(html).find("table tbody tr").length <= 0) {
1197
                    jQuery("#next").hide();
1198
                }
1199
            } else {
1200
                jQuery("#next").hide();
1201
            }
1202
        }
1203
    });
1204
    return false;
1205
}
1206
$(window).scroll(function() {
1207
    if ($(this).scrollTop() > 330) {
1208
        $(".tx-dpf-tab-container").addClass("sticky");
1209
    } else {
1210
        $(".tx-dpf-tab-container").removeClass("sticky");
1211
    }
1212
});
1213
1214
1215
var datepicker = function() {
1216
    var language = jQuery("div.tx-dpf[data-language]").first().attr("data-language");
1217
    if (!language) language = "en";
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1218
    jQuery(".datetimepicker").datetimepicker({
1219
        icons: {
1220
            time: 'far fa-clock',
1221
            date: 'fas fa-calendar-alt',
1222
            up: 'fas fa-chevron-up',
1223
            down: 'fas fa-chevron-down',
1224
            previous: 'fas fa-chevron-left',
1225
            next: 'fas fa-chevron-right',
1226
            today: 'glyphicon glyphicon-screenshot',
1227
            clear: 'far fa-trash-alt',
1228
            close: 'fas fa-times'
1229
        },
1230
        useCurrent: false,
1231
        format: "DD.MM.YYYY",
1232
        locale: language,
1233
        keepInvalid: true,
1234
    }).on("keydown", function(e){
1235
        if (e.which == 13) {
1236
            $(".datetimepicker").closest("form").submit();
1237
        }
1238
    });
1239
}
1240
var isDate = function(value) {
1241
    if (value == "") return false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1242
    var rxDatePattern = /^(\d{1,2})(\.)(\d{1,2})(\.)(\d{4})$/; //Declare Regex
1243
    var dtArray = value.match(rxDatePattern); // is format OK?
1244
    if (dtArray == null) return false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Best Practice introduced by
Comparing dtArray to null using the == operator is not safe. Consider using === instead.
Loading history...
1245
    //Checks for mm/dd/yyyy format.
1246
    var dtMonth = dtArray[3];
1247
    var dtDay = dtArray[1];
1248
    var dtYear = dtArray[5];
1249
    if (dtMonth < 1 || dtMonth > 12) {
1250
        return false;
1251
    } else if (dtDay < 1 || dtDay > 31) {
1252
        return false;
1253
    } else if ((dtMonth == 4 || dtMonth == 6 || dtMonth == 9 || dtMonth == 11) && dtDay == 31) {
1254
        return false;
1255
    } else if (dtMonth == 2) {
1256
        var isleap = (dtYear % 4 == 0 && (dtYear % 100 != 0 || dtYear % 400 == 0));
0 ignored issues
show
Best Practice introduced by
Comparing dtYear % 4 to 0 using the == operator is not safe. Consider using === instead.
Loading history...
Best Practice introduced by
Comparing dtYear % 400 to 0 using the == operator is not safe. Consider using === instead.
Loading history...
Best Practice introduced by
Comparing dtYear % 100 to 0 using the != operator is not safe. Consider using !== instead.
Loading history...
1257
        if (dtDay > 29 || (dtDay == 29 && !isleap)) return false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1258
    }
1259
    return true;
1260
}
1261
var documentListConfirmDialog = function(dialogId) {
1262
1263
    var title = '%s';
1264
1265
    jQuery(dialogId).modal({
1266
        show: false,
1267
        backdrop: 'static'
1268
    });
1269
    jQuery(dialogId).on("show.bs.modal", function(e) {
1270
        //jQuery(this).find(dialogId+"Document").attr("href", jQuery(e.relatedTarget).attr("href"));
1271
        jQuery(this).find(dialogId+"Document").attr("action", jQuery(e.relatedTarget).attr("href"));
1272
        var bodyText = jQuery(this).find(".modal-body p").html();
1273
        title = jQuery(e.relatedTarget).attr("data-documenttitle");
1274
        jQuery(this).find(".modal-body p").html(bodyText.replace("%s", title));
1275
        jQuery(e.relatedTarget).parent().parent().addClass("danger marked-for-removal");
1276
    });
1277
    jQuery(dialogId).on("hidden.bs.modal", function(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1278
        var bodyText = jQuery(this).find(".modal-body p").html();
1279
        jQuery(this).find(".modal-body p").html(bodyText.replace(title, "%s"));
1280
        jQuery(".marked-for-removal").removeClass("danger marked-for-removal");
1281
    });
1282
1283
    /*
1284
    //make reason mandatory
1285
    jQuery(dialogId+"Document").submit(function(e) {
1286
        var reason = jQuery(dialogId+"Document").find("textarea");
1287
        if (typeof reason !== 'undefined' && reason.length > 0) {
1288
            if (reason.val().trim().length == 0) {
1289
                reason.val("");
1290
                e.preventDefault();
1291
            }
1292
        }
1293
    });
1294
    */
1295
1296
    jQuery(dialogId+"ReasonSelect").on("change", function(e){
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1297
        jQuery(dialogId+"Reason").val(jQuery(this).val());
1298
    });
1299
1300
1301
1302
}
1303
1304
function addRemoveFileButton() {
1305
    $(".rem_file").unbind("click");
1306
    $(".rem_file").bind("click", function (evt) {
1307
        evt.preventDefault();
1308
        $(this).siblings(".input_file_upload").val("");
1309
    })
1310
}
1311
1312
1313
function gndNothingFound(fieldId, groupIndex) {
1314
        var gndInputField = $('.gnd[data-field="' + fieldId + '"][data-groupindex="' + groupIndex + '"]');
1315
1316
        if (gndInputField.data("old_gnd_field_value")) {
1317
            gndInputField.val(gndInputField.data("old_gnd_field_value"));
1318
        } else {
1319
            gndInputField.val();
1320
        }
1321
1322
        var gndFieldId = gndInputField.data("gndfield");
1323
        var linkedGroupIndex = gndInputField.data("groupindex");
1324
        var gndLinkedInputField = $('input[data-field="' + gndFieldId + '"][data-groupindex="' + linkedGroupIndex + '"]');
1325
1326
        if (gndLinkedInputField.data("old_gnd_field_id")) {
1327
            gndLinkedInputField.val(gndLinkedInputField.data("old_gnd_field_id"));
1328
        } else {
1329
            gndLinkedInputField.val();
1330
        }
1331
1332
        /** global: form_error_msg_nothing_found */
1333
        jQuery('<div id="gnd-nothing-found" class="alert alert-warning" role="alert"><i class="fab fa-gripfire pull-right"></i>' + form_error_msg_nothing_found + '</div>').insertBefore(gndInputField.closest(".form-container"));
0 ignored issues
show
Bug introduced by
The variable form_error_msg_nothing_found seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_nothing_found */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1334
1335
        gndInputField.bind("keypress click", function () {
1336
            jQuery("#gnd-nothing-found").remove();
1337
        });
1338
1339
    gndLinkedInputField.bind("keypress click", function () {
1340
        jQuery("#gnd-nothing-found").remove();
1341
    });
1342
1343
}
1344
1345
function setGndAutocomplete(fieldId, groupIndex) {
1346
    // GND autocomplete
1347
    var ajaxURL = $('.gnd[data-field="' + fieldId + '"][data-groupindex="' + groupIndex + '"]').attr("data-ajax");
1348
1349
    var gndInputField = $('.gnd[data-field="' + fieldId + '"][data-groupindex="' + groupIndex + '"]');
1350
    var gndFieldId = gndInputField.data("gndfield");
1351
    var linkedGroupIndex = gndInputField.data("groupindex");
1352
    var gndLinkedInputField = $('input[data-field="' + gndFieldId + '"][data-groupindex="' + linkedGroupIndex + '"]');
1353
1354
    gndInputField.attr("data-old_gnd_field_value",gndInputField.val());
1355
    gndLinkedInputField.attr("data-old_gnd_field_id",gndLinkedInputField.val());
1356
1357
    // Get the name of the parameter array (tx_dpf_...),
1358
    // the name depends on whether the call is from the frontend or the backend
1359
    var res = ajaxURL.match(/(tx_dpf\w+?)%/);
1360
    var paramName = "tx_dpf_qucosaform[search]";
1361
    if (res && res[1]) {
1362
        paramName = res[1]+"[search]";
1363
    }
1364
1365
    $('.gnd[data-field="' + fieldId + '"][data-groupindex="' + groupIndex + '"]').autocomplete({
1366
        source: function (request, response) {
1367
1368
            $('input[data-field="' + gndFieldId + '"][data-groupindex="' + linkedGroupIndex + '"]').val("");
1369
1370
            var requestData = {};
1371
            requestData[paramName] = request.term.replace(" ", "+");
1372
            $.ajax({
1373
                type: 'POST',
1374
                url: ajaxURL,
1375
                data: requestData,
1376
                dataType: 'json',
1377
                timeout: 10000,
1378
                success: function (data) {
1379
                   if (data) {
1380
                       response(data);
1381
                   } else {
1382
                       gndNothingFound(fieldId, groupIndex);
1383
                       response([]);
1384
                   }
1385
                },
1386
                error: function () {
1387
                    gndNothingFound(fieldId, groupIndex);
1388
                    response([]);
1389
                }
1390
            });
1391
        },
1392
        minLength: 3,
1393
        select: function (event, ui) {
1394
            gndFieldId = jQuery(event.target).data("gndfield");
1395
            linkedGroupIndex = jQuery(event.target).data("groupindex");
1396
            $('input[data-field="' + gndFieldId + '"][data-groupindex="' + linkedGroupIndex + '"]').val(ui.item.gnd);
1397
        },
1398
    }).autocomplete( "instance" )._renderItem = function( ul, item ) {
1399
        return $( "<li>" )
1400
            .append( "<div class='gnd-autocomplete'><span class='gnd-value' style='display:none;'>" + item.value + "</span>" +
1401
                "<span class='gnd-label'>" + item.label + "</span></div>"
1402
            )
1403
            .appendTo( ul );
1404
    };
1405
}
1406
1407
var previousNextFormPage = function() {
1408
1409
    $(".prev-next-buttons button").click(function (e) {
1410
        var activePage = $(".tx-dpf-tabs").find("li a.active").parent();
1411
        var newActivePage = activePage;
0 ignored issues
show
Unused Code introduced by
The assignment to variable newActivePage seems to be never used. Consider removing it.
Loading history...
1412
1413
        if ($(this).attr("id") == "next-form-page") {
1414
            newActivePage = activePage.next();
1415
        } else {
1416
            newActivePage = activePage.prev();
1417
        }
1418
1419
        if (newActivePage.length > 0) {
1420
            activePage.find("a").removeClass("active");
1421
            activePage.find("a").attr("aria-expanded", "false");
1422
            $(".tab-content").find("div.active").removeClass("active");
1423
1424
            newActivePage.find("a").addClass("active");
1425
            newActivePage.find("a").attr("aria-expanded", "true");
1426
            $(".tab-content").find(newActivePage.find("a").attr("href")).addClass("active");
1427
1428
            updatePrevNextButtons(newActivePage);
1429
1430
            $("html, body").animate({
1431
                scrollTop:$(".tx-dpf").offset().top
1432
            },"fast");
1433
        }
1434
1435
        e.preventDefault();
1436
1437
    });
1438
1439
    updatePrevNextButtons($(".tx-dpf-tabs a.active").parent());
1440
1441
    $(".tx-dpf-tabs a").click(function(){
1442
        updatePrevNextButtons($(this).parent());
1443
    });
1444
1445
}
1446
1447
var updatePrevNextButtons = function(activePage) {
1448
1449
    if (activePage !== undefined) {
1450
        if (activePage.prev().length < 1) {
1451
            $("#prev-form-page").addClass("disabled");
1452
        } else {
1453
            $("#prev-form-page").removeClass("disabled");
1454
        }
1455
        if (activePage.next().length < 1) {
1456
            $("#next-form-page").addClass("disabled");
1457
        } else {
1458
            $("#next-form-page").removeClass("disabled");
1459
        }
1460
    }
1461
}
1462
1463
var inputWithOptions = function() {
1464
1465
    $.widget( "custom.dropdownoptions", {
1466
        _create() {
1467
1468
            var availableTags = [];
1469
            var test = this.element
0 ignored issues
show
Unused Code introduced by
The variable test seems to be never used. Consider removing it.
Loading history...
1470
                .closest(".dropdown-options")
1471
                .find(".dropdown-options-values li")
1472
                .each(function(){
1473
                    if (jQuery(this).text().length > 0) {
1474
                        availableTags.push(jQuery(this).text());
1475
                    }
1476
                });
1477
1478
            this.element
1479
                .addClass( ".dropdown-options-input" )
1480
                .autocomplete({
1481
                    minLength: 0,
1482
                    source: availableTags
1483
                });
1484
1485
            this._createShowAllButton();
1486
        },
1487
        _createShowAllButton() {
1488
1489
            var input = this.element;
1490
1491
            wasOpen = false;
0 ignored issues
show
Bug introduced by
The variable wasOpen seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.wasOpen.
Loading history...
1492
1493
            input
1494
                .closest(".dropdown-options")
1495
                .find(".dropdown-options-toggle")
1496
                .on( "mousedown", function() {
1497
                    wasOpen = input.autocomplete( "widget" ).is( ":visible" );
0 ignored issues
show
Bug introduced by
The variable wasOpen seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.wasOpen.
Loading history...
1498
                })
1499
                .on( "click", function() {
1500
                    input.trigger( "focus" );
1501
                    if ( wasOpen ) {
1502
                        return;
1503
                    }
1504
                    input.autocomplete( "search", "" );
1505
1506
                });
1507
            input
1508
                .on( "click", function() {
1509
                    input.autocomplete( "search", "" );
1510
                });
1511
        }
1512
    });
1513
1514
    $( ".dropdown-options-input" ).dropdownoptions();
1515
}
1516
1517
var userSearch = function(group) {
1518
    if (group) {
1519
        $(group.find('.fis-user-search-input')).on('focus', delay(searchInputKeyupHandler, 500));
1520
        $(group.find('.fis-user-search-input')).on('keyup', delay(searchInputKeyupHandler, 500));
1521
        $(group.find('.fis-orga-search-input')).on('keyup', delay(searchInputKeyupHandler, 500));
1522
        $(group.find('.gnd-user-search-input')).on('keyup', delay(searchInputKeyupHandler, 500));
1523
        $(group.find('.ror-user-search-input')).on('keyup', delay(searchInputKeyupHandler, 500));
1524
        $(group.find('.zdb-user-search-input')).on('keyup', delay(searchInputKeyupHandler, 500));
1525
        $(group.find('.unpaywall-user-search-input')).on('keyup', delay(searchInputKeyupHandler, 500));
1526
        $(group.find('.orcid-user-search-input')).on('keyup', delay(searchInputKeyupHandler, 500));
1527
    } else {
1528
        $('.fis-user-search-input').on('focus', delay(searchInputKeyupHandler, 500));
1529
        $('.fis-user-search-input').on('keyup', delay(searchInputKeyupHandler, 500));
1530
        $('.fis-orga-search-input').on('keyup', delay(searchInputKeyupHandler, 500));
1531
        $('.gnd-user-search-input').on('keyup', delay(searchInputKeyupHandler, 500));
1532
        $('.ror-user-search-input').on('keyup', delay(searchInputKeyupHandler, 500));
1533
        $('.zdb-user-search-input').on('keyup', delay(searchInputKeyupHandler, 500));
1534
        $('.unpaywall-user-search-input').on('keyup', delay(searchInputKeyupHandler, 500));
1535
        $('.orcid-user-search-input').on('keyup', delay(searchInputKeyupHandler, 500));
1536
    }
1537
}
1538
1539
function delay(callback, ms) {
1540
    var timer = 0;
1541
    return function() {
1542
        var context = this, args = arguments;
1543
        clearTimeout(timer);
1544
        timer = setTimeout(function () {
1545
            callback.apply(context, args);
1546
        }, ms || 0);
1547
    };
1548
}
1549
1550
var searchInputKeyupHandler = function() {
1551
    var searchValue = $(this).val();
1552
    var groupIndex = $(this).data("groupindex");
0 ignored issues
show
Unused Code introduced by
The variable groupIndex seems to be never used. Consider removing it.
Loading history...
1553
    if (searchValue.length >= 3) {
1554
        let url = $(this).data("searchrequest");
1555
        let params = {};
1556
        params['tx_dpf_backoffice[searchTerm]'] = searchValue;
1557
        // type person or organisation
1558
        params['tx_dpf_backoffice[type]'] = $(this).closest('.modal').find("input[name^='searchTypeRadio']:checked").val();
1559
1560
        var radioType = $(this).closest('.modal').find("input[name^='searchTypeRadio']:checked").val();
1561
1562
        $.ajax({
1563
            type: "POST",
1564
            url: url,
1565
            data: params,
1566
            context: this,
1567
            success: function (data) {
1568
                var that = this;
1569
                var dataObject = JSON.parse(data);
1570
                var groupIndex = $(this).data("groupindex")
1571
                var hitListElement = $(this).parent().parent().find('.'+$(this).data("api").toLowerCase()+'-search-list-' + groupIndex + ' ul').html('');
1572
1573
                $.each(dataObject.entries, function (key, value) {
1574
                    var type = $(that).data("api").toLowerCase();
1575
                    var allData = value;
1576
1577
                    if ($(that).attr('class') === 'fis-user-search-input') {
1578
                        if (radioType == 'person') {
1579
                            if (value.organisationalUnits && value.organisationalUnits.length > 0) {
1580
                                var optionalText = value.organisationalUnits[0].titleDe;
1581
                                if (value.organisationalUnits[1]) {
1582
                                    optionalText = optionalText +', '+ value.organisationalUnits[1].titleDe
1583
                                }
1584
                            }
1585
                            hitListElement.append(listHtml(value.fullName, value.fisPersid, allData, optionalText));
0 ignored issues
show
Bug introduced by
The variable optionalText does not seem to be initialized in case value.organisationalUnit...ationalUnits.length > 0 on line 1579 is false. Are you sure the function listHtml handles undefined variables?
Loading history...
1586
                        } else if (radioType == 'organisation'){
1587
                            hitListElement.append(listHtml(value.titleDe + ' (' + value.parentOrgaName + ')', value.id, allData));
1588
                        }
1589
                    } else if ($(that).attr('class') === 'fis-orga-search-input') {
1590
                        hitListElement.append(listHtml(value.titleDe, value.id, allData));
1591
                    } else if ($(that).attr('class') === 'gnd-user-search-input') {
1592
                        if (radioType == 'person') {
1593
                            var professions = '';
1594
                            var date = '';
1595
1596
                            if (value.professionOrOccupation !== undefined) {
1597
                                $.each(value.professionOrOccupation, function (key, value) {
1598
                                    professions += value.label + ', ';
1599
                                });
1600
                                professions = professions.slice(0, -2);
1601
                            }
1602
                            if (value.dateOfBirth) {
1603
                                date = value.dateOfBirth;
1604
                            }
1605
                            if (value.dateOfDeath) {
1606
                                date += ' - ' + value.dateOfDeath;
1607
                            }
1608
                            var optionalText = '';
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable optionalText already seems to be declared on line 1580. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
1609
                            if (date) {
1610
                                optionalText = date;
1611
                            }
1612
                            if (professions) {
1613
                                if (date) {
1614
                                    optionalText += ', ';
1615
                                }
1616
                                optionalText += professions.trim();
1617
                            }
1618
                        }
1619
1620
                        hitListElement.append(listHtml(value.preferredName, value.gndIdentifier, allData, optionalText));
1621
                    } else if ($(that).attr('class') === 'ror-user-search-input') {
1622
                        var optionalText = '';
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable optionalText already seems to be declared on line 1580. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
1623
1624
                        if (allData.type) {
1625
                            optionalText += allData.type;
1626
                        }
1627
                        if (allData.aliases) {
1628
                            optionalText += allData.aliases;
1629
                        }
1630
1631
                        hitListElement.append(listHtml(value.name, value.id, allData, optionalText));
1632
                    } else if ($(that).attr('class') === 'zdb-user-search-input') {
1633
                        hitListElement.append(listHtml(value.title, value.identifier, allData, value.publisher));
1634
                    } else if ($(that).attr('class') === 'unpaywall-user-search-input') {
1635
                        hitListElement.append(listHtml(value.title, value.doi, allData, value.best_oa_location.url_for_landing_page, value.oa_status));
1636
                    } else if ($(that).attr('class') === 'orcid-user-search-input') {
1637
                        hitListElement.append(listHtml(value["given-names"] + ' ' + value["family-names"], value["orcid-id"], allData, value["orcid-id"]));
1638
                    }
1639
1640
                });
1641
                addFoundUserData();
1642
            }
1643
        });
1644
    }
1645
}
1646
1647
var listHtml = function (name, id, all = '', optionalText = '', color = '') {
1648
    JSON.stringify(all).replace(/"/g, '');
1649
1650
    if (color) {
1651
        colorHtml = '('+color+')';
0 ignored issues
show
Bug introduced by
The variable colorHtml seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.colorHtml.
Loading history...
1652
    } else {
1653
        colorHtml = '';
1654
    }
1655
1656
    var text = '';
1657
    if (optionalText) {
1658
        var text = ' (' + optionalText + ') ';
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable text already seems to be declared on line 1656. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
1659
    }
1660
    var orgaName = '';
1661
    if (all.organisationalUnits !== undefined) {
1662
        $.each(all.organisationalUnits, function(key, value) {
1663
            orgaName += value.titleDe + ', ';
1664
        });
1665
        orgaName = orgaName.slice(0, -2);
1666
    }
1667
1668
    return '<li style="margin-bottom:1rem;" class="container">' +
1669
        '<div class="row">' +
1670
        '<div class="col"><button style="margin-right:1rem;" class="btn btn-s btn-info found-user-add" type="button" data-id="' + id + '" data-surname="'+all.surname+'" data-givenname="'+all.givenName+'" data-organame="'+orgaName+'">' +
1671
        'Übernehmen' +
1672
        '</button></div>' +
1673
        '<div class="col-6">' +
1674
        name + text + colorHtml +
1675
        '</div>' +
1676
        '</div>' +
1677
        '</li>';
1678
}
1679
1680
var addFoundUserData = function () {
1681
    $('.found-user-add').on('click', function () {
1682
        var input = $(this).closest('.modal-body').find('input');
1683
1684
        // user setting modal
1685
        if (input.data('usersettings') == '1') {
1686
            $('#fisPersId').val($(this).data('id'));
1687
            $('#firstName').val($(this).data('givenname'));
1688
            $('#lastName').val($(this).data('surname'));
1689
            $('#orgaName').val($(this).data('organame'));
1690
            $(this).closest('.modal').modal('hide');
1691
        } else if (input.data('usersettings') == 'extSearch') {
1692
            $('#search-field-default-value').val($(this).data('id'));
1693
            $(this).closest('.modal').modal('hide');
1694
        } else {
1695
            setDataRequest(input.data('datarequest'), $(this).data('id'), input);
1696
        }
1697
1698
    });
1699
}
1700
1701
var setDataRequest = function(url, dataId, context) {
1702
1703
    let params = {};
1704
    params['tx_dpf_backoffice[dataId]'] = dataId;
1705
    params['tx_dpf_backoffice[groupId]'] = context.data('group');
1706
    params['tx_dpf_backoffice[groupIndex]'] = context.data('groupindex');
1707
    params['tx_dpf_backoffice[fieldIndex]'] = 0;
1708
    params['tx_dpf_backoffice[pageId]'] = context.data('page');
1709
    params['tx_dpf_backoffice[type]'] = context.closest('.modal').find("input[name^='searchTypeRadio']:checked").val();
1710
1711
    $.ajax({
1712
        type: "POST",
1713
        url: url,
1714
        data: params,
1715
        dataType: 'json',
1716
        success: function (data) {
1717
            var newKeyMapping = new Map();
1718
            // fill out data for each key
1719
            for (var key in data) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
1720
                var splitId = key.split("-");
1721
                // key without the last index (field index)
1722
                var keyWithoutFieldIndex = splitId[0] + '-' + splitId[1] + '-' + splitId[2] + '-' + splitId[3];
1723
                var isFieldRepeatable = $('.' + keyWithoutFieldIndex + '-' + '0').parent().parent().find('.add_field').length;
1724
1725
                if($('.' + key).length != 0 && $('.' + key).val() == '' || $('.' + key).length != 0 && $('.' + key).val() != '' && !isFieldRepeatable) {
0 ignored issues
show
Best Practice introduced by
Comparing $("." + key).length to 0 using the != operator is not safe. Consider using !== instead.
Loading history...
1726
                    // form field is empty and exists or form field is not empty and not repeatable, overwrite!
1727
                    $('.' + key).val(data[key]).change();
1728
                } else if ($('.' + key).length != 0 && $('.' + key).val() != '' && isFieldRepeatable) {
1729
                    // form field exists and is not empty
1730
                    // add new form input
1731
                    $('.' + keyWithoutFieldIndex + '-' + '0').parent().parent().find('.add_field').click();
1732
1733
                    // count repeated fields if not counted already
1734
                    var k = newKeyMapping.get(keyWithoutFieldIndex);
1735
                    if (typeof k == 'undefined') {
1736
                        var i = 0;
1737
                        while ($('.' + keyWithoutFieldIndex + '-' + i).length) {
1738
                            i++;
1739
                        }
1740
                    } else {
1741
                        i = k + 1;
1742
                    }
1743
1744
                    var newKey = keyWithoutFieldIndex + '-' + i;
1745
                    newKeyMapping.set(keyWithoutFieldIndex, i);
1746
1747
                    isElementLoaded('.' + newKey, key, function (element, fieldKey) {
1748
                        $(element).val(data[fieldKey]).change();
1749
                    });
1750
1751
                } else {
1752
                    // if key does not exist check if field is repeatable
1753
                    splitId = key.split("-");
1754
                    var datakey = key;
1755
                    if (splitId[4] > 0) {
1756
                        var k = newKeyMapping.get(keyWithoutFieldIndex);
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable k already seems to be declared on line 1734. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
1757
                        if (typeof k != 'undefined') {
1758
                            datakey = key;
1759
                            key = keyWithoutFieldIndex + '-' + (k + 1);
1760
                            newKeyMapping.set(keyWithoutFieldIndex, (k + 1));
1761
                        }
1762
                        // add new form input
1763
                        $('.' + keyWithoutFieldIndex + '-' + '0').parent().parent().find('.add_field').click();
1764
                        isElementLoaded('.' + key, datakey, function (element, fieldKey) {
1765
                            $(element).val(data[fieldKey]).change();
1766
                        });
1767
                    }
1768
                }
1769
            }
1770
        }
1771
    });
1772
    context.closest('.modal').modal('hide');
1773
}
1774
1775
var isElementLoaded = function (element, fieldKey, callback, counter = 0) {
1776
    if ($(element).length) {
1777
        callback($(element), fieldKey);
1778
    } else {
1779
        if (counter < 5) {
1780
            setTimeout(function () {
1781
                isElementLoaded(element, fieldKey, callback, counter++)
1782
            }, 500);
1783
        } else {
1784
            console.error("Field not repeatable or doesnt exist");
1785
        }
1786
    }
1787
}
1788
1789
var addMyUserData = function() {
1790
    $('.addMyData').on('click', function () {
1791
        setDataRequest($(this).data('ajax'), $(this).data('personid'), $(this));
1792
    });
1793
1794
    jQuery("[data-objecttype='fispersonid']").on('change', function() {
1795
        var fisPersonIdentifiers = getFisPersonIdentifiers();
1796
        toggleAddMyUserDataButton(fisPersonIdentifiers);
1797
    });
1798
1799
    var fisPersonIdentifiers = getFisPersonIdentifiers();
1800
    toggleAddMyUserDataButton(fisPersonIdentifiers);
1801
1802
    jQuery("[data-objecttype='fispersonid']").on('keyup', function() {
1803
        var fisPersonIdentifiers = getFisPersonIdentifiers();
1804
        toggleAddMyUserDataButton(fisPersonIdentifiers);
1805
    });
1806
}
1807
1808
var getFisPersonIdentifiers = function() {
1809
    fisPersonIdentifiers = [];
0 ignored issues
show
Bug introduced by
The variable fisPersonIdentifiers seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.fisPersonIdentifiers.
Loading history...
1810
    jQuery("[data-objecttype='fispersonid']").each(function() {
1811
        fisPersonIdentifiers.push(jQuery(this).val());
1812
    });
1813
1814
    return fisPersonIdentifiers;
1815
}
1816
1817
var toggleAddMyUserDataButton = function(fisPersonIdentifiers) {
1818
    var fisPersonId = jQuery('.addMyData').data('personid');
1819
    if (fisPersonIdentifiers.includes(fisPersonId)) {
1820
        jQuery('button.addMyData').hide();
1821
    } else {
1822
        jQuery('button.addMyData').show();
1823
    }
1824
}
1825
1826
var searchAgain = function (context) {
1827
    searchInputKeyupHandler.call(context);
1828
}
1829
1830
var userSearchModalFillout = function() {
1831
1832
    $('.FisSearchModal').on('hidden.bs.modal', function() {
1833
            jQuery(this).find('.fis-user-search-input').val('');
1834
            jQuery(this).find('.fis-search-results').html('');
1835
    });
1836
1837
    $('.FisSearchModal').on('shown.bs.modal', function () {
1838
        //jQuery(this).find("#orgaRadio").prop('checked', false);
1839
        //jQuery(this).find("#personRadio").prop('checked', true);
1840
        var surname = jQuery(this).closest('fieldset').find('[data-objecttype=surname]').val();
1841
        if (typeof surname !== 'undefined') {
1842
            if (surname.length > 0) {
1843
                jQuery(this).find('.fis-user-search-input').val(surname);
1844
            }
1845
        }
1846
    });
1847
1848
    $('.UnpaywallSearchModal').on('shown.bs.modal', function () {
1849
        var doiValue = $(this).closest('fieldset').find('*[data-objecttype="unpaywallDoi"]').val();
1850
        $(this).find('.unpaywall-user-search-input').val(doiValue);
1851
        searchAgain($(this).closest('.modal').find("input[type=text]")[0]);
1852
    });
1853
}
1854
1855
// Call methods for API Token generation
1856
var apiTokenEvents = function() {
1857
    $('#apiTokenGenerate').on('click', function () {
1858
        var url = $(this).data('generatetoken');
1859
        $.ajax({
1860
            type: "GET",
1861
            url: url,
1862
            dataType: 'json',
1863
            success: function (data) {
1864
                $('#showApiToken').text(data.apiToken);
1865
            }
1866
        });
1867
    });
1868
1869
    $('#apiTokenRemove').on('click', function () {
1870
        var url = $(this).data('removetoken');
1871
        $.ajax({
1872
            type: "GET",
1873
            url: url,
1874
            dataType: 'json',
1875
            success: function (data) {
1876
                if (data.success) {
1877
                    $('#apiTokenRemove').hide();
1878
                }
1879
            }
1880
        });
1881
    });
1882
}
1883
1884
// -------------------------------------------------------
1885
// Document ready
1886
// -------------------------------------------------------
1887
$(document).ready(function() {
1888
1889
    bsCustomFileInput.init();
0 ignored issues
show
Bug introduced by
The variable bsCustomFileInput seems to be never declared. If this is a global, consider adding a /** global: bsCustomFileInput */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1890
1891
    jQuery("#new-document-form").trigger("reset");
1892
    documentListConfirmDialog("#confirmDiscard");
1893
    documentListConfirmDialog("#confirmReleasePublish");
1894
    documentListConfirmDialog("#confirmReleaseActivate");
1895
    documentListConfirmDialog("#confirmActivate");
1896
    documentListConfirmDialog("#confirmInactivate");
1897
    documentListConfirmDialog("#confirmRestore");
1898
    documentListConfirmDialog("#confirmDelete");
1899
    documentListConfirmDialog("#confirmDeleteLocally");
1900
    documentListConfirmDialog("#confirmDeleteLocallySuggestion");
1901
    documentListConfirmDialog("#confirmDeleteWorkingCopy");
1902
    documentListConfirmDialog("#confirmRegister");
1903
    documentListConfirmDialog("#confirmPostpone");
1904
1905
    batchConfirmDialog("BatchSetInProgress");
1906
    batchConfirmDialog("BatchRegister");
1907
    batchConfirmDialog("BatchRemove");
1908
    batchConfirmDialog("BatchReleaseValidated");
1909
    batchConfirmDialog("BatchReleaseUnvalidated");
1910
    batchConfirmDialog("BatchBookmark");
1911
1912
    removeBookmarkHandler.init();
1913
    addBookmarkHandler.init();
1914
    batchSelectHandler.init();
1915
1916
    itemsPerPageHandler.init();
1917
1918
    extendedSearch.init();
1919
    saveExtendedSearch.init();
1920
    openExtendedSearch.init();
1921
1922
    userNotifcationSettings.init();
1923
1924
    documentFormGroupSelector.init();
1925
1926
    doctypeChange.init();
1927
1928
    datepicker();
1929
    jQuery('[data-toggle="tooltip"]').tooltip();
1930
    var $disableForm = jQuery("form[data-disabled]").attr("data-disabled");
1931
    if ($disableForm) {
1932
        jQuery(".input-field").each(function() {
1933
            jQuery(this).attr("disabled", "disabled");
1934
        });
1935
        jQuery(".rem_file_group").each(function() {
1936
            jQuery(this).attr("disabled", "disabled");
1937
        });
1938
        jQuery(".add_file_group").each(function() {
1939
            jQuery(this).attr("disabled", "disabled");
1940
        });
1941
        jQuery(".input_file_upload").each(function() {
1942
            jQuery(this).attr("disabled", "disabled");
1943
        });
1944
        jQuery(".add_field").each(function() {
1945
            jQuery(this).attr("disabled", "disabled");
1946
        });
1947
        jQuery(".add_group").each(function() {
1948
            jQuery(this).attr("disabled", "disabled");
1949
        });
1950
        jQuery(".rem_field").each(function() {
1951
            jQuery(this).attr("disabled", "disabled");
1952
        });
1953
        jQuery(".rem_group").each(function() {
1954
            jQuery(this).attr("disabled", "disabled");
1955
        });
1956
        jQuery(".fill_out_service_urn").each(function() {
1957
            jQuery(this).attr("disabled", "disabled");
1958
        });
1959
    }
1960
    buttonFillOutServiceUrn();
1961
    jQuery(".tx-dpf").on("click", ".rem_group", function() {
1962
        jQuery(this).parents("fieldset").fadeOut(300, function() {
1963
            jQuery(this).remove();
1964
            var fisPersonIdentifiers = getFisPersonIdentifiers();
1965
            toggleAddMyUserDataButton(fisPersonIdentifiers);
1966
        });
1967
        return false;
1968
    });
1969
    jQuery(".tx-dpf").on("click", ".rem_file_group", deleteFile);
1970
    jQuery(".tx-dpf").on("click", ".rem_secondary_upload", function() {
1971
        var dataIndex = jQuery(this).data("index");
0 ignored issues
show
Unused Code introduced by
The variable dataIndex seems to be never used. Consider removing it.
Loading history...
1972
        jQuery(this).parents(".fs_file_group").fadeOut(300, function() {
1973
            jQuery(this).remove();
1974
        });
1975
        return false;
1976
    });
1977
    jQuery(".tx-dpf").on("click", ".rem_field", function() {
1978
        var dataIndex = jQuery(this).data("index");
0 ignored issues
show
Unused Code introduced by
The variable dataIndex seems to be never used. Consider removing it.
Loading history...
1979
        var dataField = jQuery(this).data("field");
0 ignored issues
show
Unused Code introduced by
The variable dataField seems to be never used. Consider removing it.
Loading history...
1980
        jQuery(this).parents(".form-group").fadeOut(300, function() {
1981
            jQuery(this).remove();
1982
        });
1983
        return false;
1984
    });
1985
    // Add metadata group
1986
    jQuery(".tx-dpf").on("click", ".add_group", function(e) {
1987
        addGroup(e.target);
1988
        return false;
1989
    });
1990
    jQuery(".tx-dpf").on("click", ".add_file_group", function(e) {
1991
        addGroup(e.target);
1992
        return false;
1993
    });
1994
1995
    jQuery(".tx-dpf").on("click", ".add_field", addField);
1996
    jQuery(".tx-dpf").on("click", ".fill_out_service_urn", fillOutServiceUrn);
1997
    jQuery(".tx-dpf").on("keyup", "input.urn", buttonFillOutServiceUrn);
1998
    jQuery(".tx-dpf").on("click", "#next", continuousScroll);
1999
    jQuery(".form-submit").on("click", "#save", validateFormAndSave);
2000
2001
    if (
2002
        typeof(deactivate_mandatory_check_on_save_locally) == "undefined"
0 ignored issues
show
Bug introduced by
The variable deactivate_mandatory_check_on_save_locally seems to be never declared. If this is a global, consider adding a /** global: deactivate_m...heck_on_save_locally */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
2003
        || deactivate_mandatory_check_on_save_locally.length == 0
0 ignored issues
show
Best Practice introduced by
Comparing deactivate_mandatory_check_on_save_locally.length to 0 using the == operator is not safe. Consider using === instead.
Loading history...
2004
    ) {
2005
        jQuery(".form-submit").on("click", "#saveLocalDocument", validateFormAndSave);
2006
        jQuery(".form-submit").on("click", "#saveCreate", validateFormAndSave);
2007
    }
2008
2009
    jQuery(".form-submit").on("click", "#validate", validateFormOnly);
2010
2011
    // hide 'more results' link
2012
    var countResults = $("#search-results :not(thead) tr").length;
2013
    var resultCount = $("#next").data("resultCount");
2014
2015
    if (countResults < resultCount) {
2016
        jQuery("#next").hide();
2017
    }
2018
2019
    addRemoveFileButton();
2020
2021
    previousNextFormPage();
2022
2023
    var gnd = jQuery(".gnd");
2024
    if(gnd.length > 0) {
2025
        gnd.each(function() {
2026
            setGndAutocomplete(jQuery(this).data("field"),  jQuery(this).data("groupindex"));
2027
        });
2028
    }
2029
2030
    selectFilter('doctype-filter');
2031
    selectFilter('persons-filter', true);
2032
    selectFilter('aliasState-filter');
2033
    selectFilter('year-filter', true);
2034
    selectFilter('hasFiles-filter');
2035
    selectFilter('universityCollection-filter');
2036
    selectFilter('creatorRole-filter');
2037
2038
    // Remove the title hover for the filter elements.
2039
    jQuery(".select2-selection__rendered").each(function(){
2040
        jQuery(this).removeAttr("title");
2041
    });
2042
2043
    selectSort();
2044
2045
    toggleBulkImportRecord();
2046
    toggleBulkImportAuthorSearch();
2047
    toggleDiscardedFilter();
2048
    toggleBookmarksOnly();
2049
    inputWithOptions();
2050
2051
    apiTokenEvents();
2052
2053
    userSearch();
2054
    addMyUserData();
2055
    userSearchModalFillout();
2056
    $('.modal').on('shown.bs.modal', function() {
2057
        $(this).find('[autofocus]').focus();
2058
        // new search if checkbox has changed
2059
        $(this).find("#orgaRadio").on('change', function () {
2060
            searchAgain($(this).closest('.modal').find("input[type=text]")[0]);
2061
        });
2062
        $(this).find("#personRadio").on('change', function () {
2063
            searchAgain($(this).closest('.modal').find("input[type=text]")[0]);
2064
        });
2065
    });
2066
2067
    $('.double-scroll').doubleScroll();
2068
});
2069